package com.lz.service.lg.impl;

import com.lz.entity.Customer;
import com.lz.entity.EquipmentSheet;
import com.lz.entity.InsuranceSheet;
import com.lz.entity.MortgageSheet;
import com.lz.service.lg.FindCustomerService;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: 刘刚
 * @：创建于： 2018/11/3 19:22
 */
@Service
public class FindCustomerServiceImpl implements FindCustomerService {
    @Autowired
    private SessionFactory sessionFactory;
    @Override
    public List<Customer> findCustomer() {
        Session session = sessionFactory.openSession();
        String hql1 = "from MortgageSheet ms where ms.mortgageSheetState = '已完成'";
        String hql2 = "from InsuranceSheet is where is.insuranceSheetState = '已完成'";
        String hql3 = "from EquipmentSheet es where es.equipmentSheetState = '已完成'";
        Query query1 = session.createQuery(hql1);
        Query query2 = session.createQuery(hql2);
        Query query3 = session.createQuery(hql3);
        List<MortgageSheet> list = query1.list();
        List<InsuranceSheet> list2 = query2.list();
        List<EquipmentSheet> list3 = query3.list();
        List<Customer> customers = new ArrayList<>();
        for (MortgageSheet ms:
        list) {
            customers.add(ms.getCustomer());
        }
        for (InsuranceSheet is:
        list2) {
            customers.add(is.getCustomer());
        }
        for (EquipmentSheet es:
        list3) {
            customers.add(es.getCustomer());
        }
        return customers;
    }
}
